home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 80 / CD Actual 80 Julio-Agosto 2003.iso / Linux / LinuxGazette / lg / issue69 / misc / nielsen / Custom.sql < prev    next >
Encoding:
Text File  |  2002-08-14  |  2.8 KB  |  74 lines

  1. ---          Custom Sample SQL for Perl/PostgreSQL version 0.1
  2.  
  3. ---                       Copyright 2001, Mark Nielsen
  4. ---                            All rights reserved.
  5. ---    This Copyright notice was copied and modified from the Perl 
  6. ---    Copyright notice. 
  7. ---    This program is free software; you can redistribute it and/or modify
  8. ---    it under the terms of either:
  9.  
  10. ---        a) the GNU General Public License as published by the Free
  11. ---        Software Foundation; either version 1, or (at your option) any
  12. ---        later version, or
  13.  
  14. ---        b) the "Artistic License" which comes with this Kit.
  15.  
  16. ---    This program is distributed in the hope that it will be useful,
  17. ---    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ---    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See either
  19. ---    the GNU General Public License or the Artistic License for more details.
  20.  
  21. ---    You should have received a copy of the Artistic License with this
  22. ---    Kit, in the file named "Artistic".  If not, I'll be glad to provide one.
  23.  
  24. ---    You should also have received a copy of the GNU General Public License
  25. ---   along with this program in the file named "Copying". If not, write to the 
  26. ---   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
  27. ---    02111-1307, USA or visit their web page on the internet at
  28. ---    http://www.gnu.org/copyleft/gpl.html.
  29.  
  30. drop function clean_text (text);
  31. CREATE FUNCTION  clean_text (text) RETURNS text AS '
  32.   my $Text = shift;
  33.     # Get rid of whitespace in front. 
  34.   $Text =~ s/^\\s+//;
  35.     # Get rid of whitespace at end. 
  36.   $Text =~ s/\\s+$//;
  37.     # Get rid of anything not text.
  38.   $Text =~ s/[^ a-z0-9\\/\\`\\~\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\-\\_\\=\\+\\\\\\|\[\\{\\]\\}\\;\\:\\''\\"\\,\\<\\.\\>\\?\\t\\n]//gi;
  39.     # Replace all multiple whitespace with one space. 
  40.   $Text =~ s/\\s+/ /g;
  41.   return $Text;
  42. ' LANGUAGE 'plperl';
  43.  -- Just to show you what this function cleans up. 
  44. select clean_text ('       ,./<>?aaa aa      !@#$%^&*()_+| ');
  45.  
  46. drop function clean_alpha (text);
  47. CREATE FUNCTION  clean_alpha (text) RETURNS text AS '
  48.   my $Text = shift;
  49.   $Text =~ s/[^a-z0-9_]//gi;
  50.   return $Text;
  51. ' LANGUAGE 'plperl';
  52.  -- Just to show you what this function cleans up. 
  53. select clean_alpha ('       ,./<>?aaa aa      !@#$%^&*()_+| ');
  54.  
  55. drop function clean_numeric (text);
  56. CREATE FUNCTION  clean_numeric (text) RETURNS int4 AS '
  57.   my $Text = shift;
  58.   $Text =~ s/[^0-9]//gi;
  59.   return $Text;
  60. ' LANGUAGE 'plperl';
  61.  -- Just to show you what this function cleans up.
  62. select clean_numeric ('       ,./<>?aaa aa      !@#$%^&*()_+| ');
  63.  
  64. drop function clean_numeric (int4);
  65. CREATE FUNCTION  clean_numeric (int4) RETURNS int4 AS '
  66.   my $Text = shift;
  67.   $Text =~ s/[^0-9]//gi;
  68.   return $Text;
  69. ' LANGUAGE 'plperl';
  70.  -- Just do show you what this function cleans up.
  71. select clean_numeric (1111);
  72.  
  73.  
  74.